<?php

/*
+--------------------------------------------------------------------------
|   Invision Power Board
|   =============================================
|   by Matthew Mecham
|   (c) 2001 - 2006 Invision Power Services, Inc.
|   
|   =============================================
|   
|   
+---------------------------------------------------------------------------
|   > $Date: 2009-04-20 11:35:56 -0400 (Mon, 20 April 2009) $
|   > $Revision: 5 $
|   > $Author: BabyWolf $
+---------------------------------------------------------------------------
|
|   > Shop functions
|   > Module written by BabyWolf
|   > Date started: 20th April 2009
|
|	> Module Version Number: 1.0.0
|   > DBA Checked: 
+--------------------------------------------------------------------------
*/

if ( ! defined( 'IN_ACP' ) )
{
	print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'admin.php'.";
	exit();
}

class ad_shops {

	function auto_run()
	{
		$this->ipsclass->admin->nav[]       = array( "{$this->ipsclass->form_code}", "Shop Management" );

		//-----------------------------------------
		// Load template
		//-----------------------------------------

		$this->html = $this->ipsclass->acp_load_template( 'cp_skin_shops' );

		

		//-----------------------------------------

		$this->ipsclass->DB->sql_get_version();

		$this->true_version  = $this->ipsclass->DB->true_version;
		$this->mysql_version = $this->ipsclass->DB->mysql_version;

		switch($this->ipsclass->input['code'])
		{
			// Item functions
			case 'item_new':
				$this->item_form('add');
				break;
			
			case 'item_showedit':
				$this->item_form('edit');
				break;
			
			case 'item_add':
				$this->item_save('add');
				break;
			
			case 'item_edit':
				$this->item_save('edit');
				break;
				
			case 'item_delete':
				$this->item_delete();
				break;
				
			case 'items_view':
				$this->item_view();
				break;
				
			// Category functions
			case 'category_delete':
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':remove' );
				$this->category_delete();
				break;

			case 'category_new':
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' );
				$this->category_form('add');
				break;

			case 'category_showedit':
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
				$this->category_form('edit');
				break;

			case 'category_add':
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' );
				$this->category_save('add');
				break;

			case 'category_edit':
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
				$this->category_save('edit');
				break;

			//-----------------------------------------
			default:
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':' );
				$this->shop_start();
				break;
		}

	}

	function item_save($type='add') {
		//-----------------------------------------
		// INIT
		//-----------------------------------------

		$item_name 			= $this->ipsclass->input['itemName'];
		$item_desc 			= $this->ipsclass->input['itemDesc'];
		$item_price 		= $this->ipsclass->input['itemPrice'];
		$item_quantity 		= $this->ipsclass->input['itemQuantity'];
		$item_catid 		= $this->ipsclass->input['catid'];
		$item_update_field	= $this->ipsclass->input['itemUpdateField'];
		$item_index 		= $this->ipsclass->input['itemIndex'];
		$item_type			= $this->ipsclass->input['itemType'];
		//-----------------------------------------
		// Check...
		//-----------------------------------------

		if (!$item_name)
		{
			$this->ipsclass->main_msg = "You must enter item name.";
			$this->item_form();
			return;
		}
		
		if(!$item_price) {
			$this->ipsclass->main_msg = "You must enter item price.";
			$this->item_form();
			return;
		}
		
		if(!is_numeric($item_price) || $item_price!=intval($item_price)) {
			$this->ipsclass->main_msg = "Item price must be number.";
			$this->item_form();
			return;
		}
		
		if(!$item_quantity) {
			$this->ipsclass->main_msg = "You must enter item quantity.";
			$this->item_form();
			return;	
		}
		
		if(!is_numeric($item_quantity) || $item_quantity!=intval($item_quantity)) {
			$this->ipsclass->main_msg = "Item quantity must be number.";
			$this->item_form();
			return;	
		}
		
		// Get file extension
		$file_name = $_FILES['imageupload']['name'];
		$photo_name = $_FILES['photoupload']['name'];
		
		$image_extension = substr($file_name,strrpos($file_name,".")+1);
		$photo_extension = substr($photo_name,strrpos($photo_name,".")+1);
		
		if($type=='add') {
			$allow_array = array('jpg','png','gif');
			
			if(!in_array($image_extension, $allow_array)) {
				$this->ipsclass->main_msg = "You must upload JPEG, GIF, PNG file for item image.";
				$this->item_form();
				return;	
			}
			
			if($_FILES['flashupload']['type']!='application/x-shockwave-flash'
			&& $_FILES['flashupload']['name']) {
				$this->ipsclass->main_msg = "You must upload Flash file for item flash.";
				$this->item_form();
				return;	
			}
			
			if($photo_extension != 'gif') {
				$this->ipsclass->main_msg = "You must upload GIF file for item photo.";
				$this->item_form();
				return;	
			}
		}
		
		// Select the information of category
		$this->ipsclass->DB->simple_construct(array('select' => '*',
													'from'	 => 'shop_categories',
													'where'	 => 'catId='.$item_catid
													));
		
		$this->ipsclass->DB->simple_exec();
		$category = $this->ipsclass->DB->fetch_row();
		
		$real_path = $this->ipsclass->vars['upload_dir']."/shops/".$category['catPath']."/";
		
		//-----------------------------------------
		// check...
		//-----------------------------------------

		$array = array( 'itemName'  		=> $item_name,
						'itemDesc'  		=> $item_desc,
						'itemPrice' 		=> $item_price,
						'itemQuantity' 		=> $item_quantity,
						'itemIndex'			=> $item_index,
						'itemCatId' 		=> $item_catid,
						'itemUpdateField'	=> $item_update_field,
						'itemType'			=> $item_type
					 );

		// Make sure not update image extension if user not browse new file
		if($image_extension) $array['itemImageExt']		= $image_extension;
		
		if ( $type == 'add' )
		{
			$this->ipsclass->DB->do_insert( 'shop_items', $array );
			$this->ipsclass->main_msg = 'New Item Added';
			
			// Get id for file name
			$item_id = $this->ipsclass->DB->get_insert_id();
			
			$image_file_path = $real_path.$item_id.".".$image_extension;
			$flash_file_path = $real_path.$item_id.".swf";
			$photo_file_path = $real_path.$item_id."_photo.gif";
			
			// Move item image
			move_uploaded_file($_FILES['imageupload']['tmp_name'],$image_file_path);
			// Move item photo
			move_uploaded_file($_FILES['photoupload']['tmp_name'],$photo_file_path);
			
			// Move item flash
			if($_FILES['flashupload']['name'])
				move_uploaded_file($_FILES['flashupload']['tmp_name'],$flash_file_path);
		}
		else
		{
			$item_id = $this->ipsclass->input['id'];
			$this->ipsclass->DB->do_update( 'shop_items', $array, 'itemId='.$item_id);
			$this->ipsclass->main_msg = 'New Item Edited';
			
			// Move item image if user choose file to update
			if($_FILES['imageupload']['name']) {
				move_uploaded_file($_FILES['imageupload']['tmp_name'],$real_path.$item_id.".".$image_extension);
			}
			
			// Move item photo if user choose file to update
			if($_FILES['photoupload']['name']) {
				move_uploaded_file($_FILES['photoupload']['tmp_name'],$real_path.$item_id."_photo.gif");
			}
			
			// Move the item flash if user choose file to update
			if($_FILES['flashupload']['name']) {
				move_uploaded_file($_FILES['flashupload']['tmp_name'],$real_path.$item_id.".swf");
			}
		}

		$this->item_view($item_catid);
	}
	
	function item_form($type='add') {
		$this->ipsclass->admin->page_title  = "Shop Item Management";
		$this->ipsclass->admin->page_detail = "This section contains all the functions to manage your IPB shop.";
		$this->ipsclass->admin->nav[]       = array( '', "Add/Edit Shop Item" );

		if ( $type == 'add' )
		{
			$formcode = 'item_add';
			$title    = "Create New Item";
			$button   = "Add Item";
			$item = array( 	'itemName' 	 => '',
							'itemDesc' 	 => '',
							'itemPrice'	 => 0,
							'itemIndex'	 => 0,
							'itemQuantity'=> 0,
							'itemCatId'	 => $this->ipsclass->input['catid'],
							'itemUrl'	 => '',
							'itemType'	 => 0,
							'itemUpdateField'	=> 0,
							   );

		}
		else
		{
			$item = $this->ipsclass->DB->simple_exec_query( array( 'select' => '*', 'from' => 'shop_items', 'where' => 'itemId='.intval($this->ipsclass->input['id']) ) );

			if ( ! $item['itemId']) {
				$this->ipsclass->main_msg = "No ID was passed, please try again.";
				$this->shop_start();
			}

			$formcode = 'item_edit';
			$title    = "Edit Item <u>".$item['itemName']."</u>";
			$button   = "Edit Item";
		}

		$this->ipsclass->admin->page_detail = '&nbsp;';
		$this->ipsclass->admin->page_title  = $title;

		//-----------------------------------------
		// start form
		//-----------------------------------------

		$this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'code'   , $formcode ),
																			 2 => array( 'act'    , 'shop'      ),
																			 3 => array( 'id'     , $this->ipsclass->input['id'] ),
																			 4 => array( 'section', 'content' ),
																			 5 => array( 'MAX_FILE_SIZE' , '10000000000' ),
																	), "uploadform", " enctype='multipart/form-data'"      );

		// Get categories
		$this->ipsclass->DB->simple_construct(array('select' => '*',
													'from'	 => 'shop_categories',
													));
		$this->ipsclass->DB->simple_exec();
		
		$categories = array();
		while($category = $this->ipsclass->DB->fetch_row()) {
			$categories[] = array($category['catId'],$category['catName']);
		}
		
		// Define item type
		$item_types = array(	array(0, 'Animals'		),
								array(1, 'Backgrounds'	),
								array(2, 'Functions'	),
								array(3, 'Houses'		),
								array(4, 'Cars'			),
								array(5, 'Motobikes'	),
								array(6, 'Plants'		),
								array(7, 'Toys'			),
								array(8, 'Foods'		)
								);
		//-----------------------------------------
		// start table
		//-----------------------------------------

		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "40%" );
		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "60%" );

		//-----------------------------------------
		// um..
		//-----------------------------------------

		$this->ipsclass->html .= $this->ipsclass->adskin->start_table( $title );

		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Category</b>" ,
												  			   $this->ipsclass->adskin->form_dropdown( 'catid', $categories, ( isset($_POST['catid']) AND $_POST['catid'] ) ? $_POST['catid'] : $item['itemCatId'] )
										 		    	)      );
										 		    	
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Item Name</b>" ,
												  			   $this->ipsclass->adskin->form_input( 'itemName', ( isset($_POST['itemName']) AND $_POST['itemName'] ) ? $_POST['itemName'] : $item['itemName'] )
										 		    	)      );

		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Item Description</b>" ,
												  			   $this->ipsclass->adskin->form_textarea( 'itemDesc', ( isset($_POST['itemDesc']) AND $_POST['itemDesc'] ) ? $_POST['itemDesc'] : $item['itemDesc'] )
										 		    	)      );

		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Item Price</b>" ,
												  			   $this->ipsclass->adskin->form_input( 'itemPrice', ( isset($_POST['itemPrice']) AND $_POST['itemPrice'] ) ? $_POST['itemPrice'] : $item['itemPrice'] )
										 		    	)      );

		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Item Quantity</b>" ,
												  			   $this->ipsclass->adskin->form_input( 'itemQuantity', ( isset($_POST['itemQuantity']) AND $_POST['itemQuantity'] ) ? $_POST['itemQuantity'] : $item['itemQuantity'] )
										 		    	)      );

		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Item Index</b><div style='color:gray'>The index for overlay layer.</div>" ,
												  			   $this->ipsclass->adskin->form_input( 'itemIndex', ( isset($_POST['itemIndex']) AND $_POST['itemIndex'] ) ? $_POST['itemIndex'] : $item['itemIndex'] )
										 		    	)      );
										 		    											 		    	
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Image photo</b><div style='color:gray'>Only allow GIF.</div>" ,
												  			   $this->ipsclass->adskin->form_upload( 'photoupload')
										 		    	)      );
										 		    	
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Image file</b><div style='color:gray'>Only allow JPEG, PNG, GIF.</div>" ,
												  			   $this->ipsclass->adskin->form_upload( 'imageupload')
										 		    	)      );
		
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Flash file</b>" ,
												  			   $this->ipsclass->adskin->form_upload( 'flashupload')
										 		    	)      );

		
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Item type</b>" ,
												  			   $this->ipsclass->adskin->form_dropdown( 'itemType', $item_types, ( isset($_POST['itemType']) AND $_POST['itemType'] ) ? $_POST['itemType'] : $item['itemType'] )
										 		    	)      );
										 		    	
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Custom field ID to update</b><div style='color:gray'>The number you input here will be the ID of user custom field, just enter if this item update user information.</div>" ,
												  			   $this->ipsclass->adskin->form_input( 'itemUpdateField',( isset($_POST['itemUpdateField']) AND $_POST['itemUpdateField'] ) ? $_POST['itemUpdateField'] : $item['itemUpdateField'] )
										 		    	)      );
										 		    	
		$this->ipsclass->html .= $this->ipsclass->adskin->end_form( $button );

		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();

		$this->ipsclass->admin->output();
	}
	
	function item_delete() {
		if ( $this->ipsclass->input['id'] )
		{
			$this->ipsclass->DB->simple_exec_query( array( 'delete' => 'shop_items', 'where' => 'itemId='.intval($this->ipsclass->input['id']) ) );

			$this->ipsclass->main_msg = "Item Removed";
		}

		$this->item_view($this->ipsclass->input['catid']);
	}
	
	function item_view($catId=0) {
		
		$catId = $catId?$catId:$this->ipsclass->input['catid'];
		
		$this->ipsclass->admin->page_title  = "Category management";
		$this->ipsclass->admin->page_detail = "This section contains all the functions to manage your IPB shop.";

		// Get category
		$this->ipsclass->DB->simple_construct(array('select'=> '*', 
													'from'	=> 'shop_categories',
													'where'	=> 'catId='.$catId
													));
		$this->ipsclass->DB->simple_exec();
		
		$category = $this->ipsclass->DB->fetch_row();
		
		//-----------------------------------------
		// start table
		//-----------------------------------------

		$this->ipsclass->adskin->td_header[] = array( "Image "  , "5%" );
		$this->ipsclass->adskin->td_header[] = array( "Name"  , "50%" );
		$this->ipsclass->adskin->td_header[] = array( "Index"  , "10%" );
		$this->ipsclass->adskin->td_header[] = array( "Price"  , "15%" );
		$this->ipsclass->adskin->td_header[] = array( "Quantity"  , "15%" );
		$this->ipsclass->adskin->td_header[] = array( "Action"  , "5%" );

		$basic_title = "<table cellpadding='0' cellspacing='0' border='0' width='100%'>
						<tr>
						 <td align='left' width='40%' style='font-size:12px; vertical-align:middle;font-weight:bold; color:#FFF;'>Items in <u>{$category['catName']}</u></td>
						 <td align='right' width='60%' style='padding-right: 10px'><input class='realbutton' onclick=\"self.location.href='{$this->ipsclass->base_url}&{$this->ipsclass->form_code}&code=item_new&catid={$this->ipsclass->input['catid']}'\" type='button' value='Add New Item' /></td>
						</tr>
						</table>";

		$this->ipsclass->html .= $this->ipsclass->adskin->start_table($basic_title);

		//-----------------------------------------
		// Get categories
		//-----------------------------------------

		$this->ipsclass->DB->simple_construct( array('select' 	=> '*', 
													 'from' 	=> 'shop_items',
													 'where'	=> 'itemCatId='.$this->ipsclass->input['catid'],
													 'order'	=> 'itemIndex'
														));
		$this->ipsclass->DB->simple_exec();

		while( $item = $this->ipsclass->DB->fetch_row() )
		{
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<div align='center'><img width='70' src='{$this->ipsclass->vars['upload_url']}/shops/{$category['catPath']}/{$item['itemId']}_photo.gif' border='0' alt='{$item['itemName']}' /></div>",
																    "<a href='{$this->ipsclass->base_url}&{$this->ipsclass->form_code}&code=item_showedit&id={$item['itemId']}' title='Click to edit this item'><b>{$item['itemName']}</b></a><div style='color:gray'>{$item['itemDesc']}</div>" ,
																	"<b><span style='color:red'>{$item['itemIndex']}</span></b>" ,
																	"<b><span style='color:red'>\${$item['itemPrice']}</span></b>" ,
																	"<b><span style='color:blue'>{$item['itemQuantity']}</span></b>",
												  				   array("<div align='center' style='white-space:nowrap'>
												  				          <a href='{$this->ipsclass->base_url}&{$this->ipsclass->form_code}&code=item_showedit&id={$item['itemId']}' title='Edit this item'><img src='{$this->ipsclass->adskin->img_url}/images/icons_menu/edit.gif' border='0' alt='Edit'  /></a>
																          <a href='{$this->ipsclass->base_url}&{$this->ipsclass->form_code}&code=item_delete&id={$item['itemId']}&catid={$category['catId']}' title='Delete this item'><img src='{$this->ipsclass->adskin->img_url}/images/icons_menu/delete.gif' border='0' alt='Delete'  /></a>
																          {$in_dev_extra}
																          </div>", 1, 'tablerow3' )
										 					  )      );
		}

		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();

		$this->ipsclass->admin->output();
	}
	
	//-----------------------------------------
	//
	// Delete setting group
	//
	//-----------------------------------------

	function category_delete()
	{
		if ( $this->ipsclass->input['id'] )
		{
			$this->ipsclass->DB->simple_exec_query( array( 'delete' => 'shop_categories', 'where' => 'catId='.intval($this->ipsclass->input['id']) ) );

			$this->ipsclass->main_msg = "Category Removed";
		}

		$this->shop_start();
	}

	//-----------------------------------------
	// Category Save Form
	//-----------------------------------------

	function category_save($type='add')
	{
		//-----------------------------------------
		// INIT
		//-----------------------------------------

		$category_name = $this->ipsclass->input['categoryName'];

		//-----------------------------------------
		// Check...
		//-----------------------------------------

		if ( ! $category_name )
		{
			$this->ipsclass->main_msg = "You must enter category name.";
			$this->category_form();
			return;
		}
		
		$category_desc = $this->ipsclass->input['categoryDesc'];
		$category_path = $this->ipsclass->input['categoryPath']?$this->ipsclass->input['categoryPath']:'items';
		$real_path = $this->ipsclass->vars['upload_dir']."/shops/".$category_path;
		
		//-----------------------------------------
		// check...
		//-----------------------------------------

		$array = array( 'catName' => $category_name,
						'catDesc' => $category_desc,
						'catPath' => $category_path
					 );


		if ( $type == 'add' )
		{
			$this->ipsclass->DB->do_insert( 'shop_categories', $array );
			$this->ipsclass->main_msg = 'New Category Added';
		}
		else
		{
			$this->ipsclass->DB->do_update( 'shop_categories', $array, 'catId='.intval($this->ipsclass->input['id']) );
			$this->ipsclass->main_msg = 'New Category Edited';
		}

		// Check if folder is existed yet
		if(!file_exists($real_path)) {
			mkdir($real_path);
		}
		
		$this->shop_start();
	}

	//-----------------------------------------
	//
	// New setting form
	//
	//-----------------------------------------

	function category_form( $type='add' )
	{
		$this->ipsclass->admin->page_title  = "Shop Management";
		$this->ipsclass->admin->page_detail = "This section contains all the functions to manage your IPB shop.";
		$this->ipsclass->admin->nav[]       = array( '', "Add/Edit Category" );

		if ( $type == 'add' )
		{
			$formcode = 'category_add';
			$title    = "Create New Category";
			$button   = "Add Category";
			$category = array( 'catName' 	=> '',
							   'catDesc' 	=> '',
							   'catPath'		=> '',
							   );

		}
		else
		{
			$category = $this->ipsclass->DB->simple_exec_query( array( 'select' => '*', 'from' => 'shop_categories', 'where' => 'catId='.intval($this->ipsclass->input['id']) ) );

			if ( ! $category['catId']) {
				$this->ipsclass->main_msg = "No ID was passed, please try again.";
				$this->shop_start();
			}

			$formcode = 'category_edit';
			$title    = "Edit Category <u>".$category['catName']."</u>";
			$button   = "Edit Category";
		}

		$this->ipsclass->admin->page_detail = '&nbsp;';
		$this->ipsclass->admin->page_title  = $title;

		//-----------------------------------------
		// start form
		//-----------------------------------------

		$this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'code'   , $formcode ),
																			 2 => array( 'act'    , 'shop'      ),
																			 3 => array( 'id'     , $this->ipsclass->input['id'] ),
																			 4 => array( 'section', 'content' ),
																	)      );

		//-----------------------------------------
		// start table
		//-----------------------------------------

		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "40%" );
		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "60%" );

		//-----------------------------------------
		// um..
		//-----------------------------------------

		$this->ipsclass->html .= $this->ipsclass->adskin->start_table( $title );
												 		    	
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Category Name</b>" ,
												  			   $this->ipsclass->adskin->form_input( 'categoryName', ( isset($_POST['categoryName']) AND $_POST['categoryName'] ) ? $_POST['categoryName'] : $category['catName'] )
										 		    	)      );

		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Category Description</b>" ,
												  			   $this->ipsclass->adskin->form_textarea( 'categoryDesc', ( isset($_POST['categoryDesc']) AND $_POST['categoryDesc'] ) ? $_POST['categoryDesc'] : $category['catDesc'] )
										 		    	)      );

		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Category Path</b><div style='color:gray'>The path that store the image items.<br />Example: if you enter <b>pets</b>, your image in this category will be saved to {$this->ipsclass->vars['upload_url']}/shops/<b>pets</b></div>" ,
												  			   $this->ipsclass->adskin->form_input( 'categoryPath', ( isset($_POST['catPath']) AND $_POST['catPath'] ) ? $_POST['catPath'] : $category['catPath'] )
										 		    	)      );

		
		$this->ipsclass->html .= $this->ipsclass->adskin->end_form( $button );

		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();

		$this->ipsclass->admin->output();

	}

	//-----------------------------------------
	// Settings Start
	//-----------------------------------------

	function shop_start()
	{
		$this->ipsclass->admin->page_title  = "Category management";
		$this->ipsclass->admin->page_detail = "This section contains all the functions to manage your IPB shop.";

		//-----------------------------------------
		// start table
		//-----------------------------------------

		$this->ipsclass->adskin->td_header[] = array( " "  , "2%" );
		$this->ipsclass->adskin->td_header[] = array( "Category name"  , "60%" );
		$this->ipsclass->adskin->td_header[] = array( "Path"  , "28%" );
		$this->ipsclass->adskin->td_header[] = array( "Action"  , "10%" );

		$basic_title = "<table cellpadding='0' cellspacing='0' border='0' width='100%'>
						<tr>
						 <td align='left' width='40%' style='font-size:12px; vertical-align:middle;font-weight:bold; color:#FFF;'>Category management</td>
						</tr>
						</table>";

		$this->ipsclass->html .= $this->ipsclass->adskin->start_table($basic_title);

		//-----------------------------------------
		// Get categories
		//-----------------------------------------

		$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'shop_categories'));
		$this->ipsclass->DB->simple_exec();

		while( $category = $this->ipsclass->DB->fetch_row() )
		{
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<div align='center'><img src='{$this->ipsclass->adskin->img_url}/images/settings_folder.gif' border='0' alt='Folder' /></div>",
																   "<div><a href='{$this->ipsclass->base_url}&{$this->ipsclass->form_code}&code=items_view&catid={$category['catId']}' title='Click to manage item in this category'><b>{$category['catName']}</b></a><div style='color:gray'>{$category['catDesc']}</div>" ,
																	"<b>{$category['catPath']}</b>" ,
												  				   array("<div align='center' style='white-space:nowrap'>
												  				          <a href='{$this->ipsclass->base_url}&{$this->ipsclass->form_code}&code=category_showedit&id={$category['catId']}' title='Edit this category'><img src='{$this->ipsclass->adskin->img_url}/images/icons_menu/edit.gif' border='0' alt='Edit'  /></a>
																          <a href='{$this->ipsclass->base_url}&{$this->ipsclass->form_code}&code=category_delete&id={$category['catId']}' title='Delete this category'><img src='{$this->ipsclass->adskin->img_url}/images/icons_menu/delete.gif' border='0' alt='Delete'  /></a>
																          {$in_dev_extra}
																          </div>", 1, 'tablerow3' )
										 					  )      );
		}

		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();


		//-----------------------------------------
		// Import partial settings?
		//-----------------------------------------

		$this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'code'          , 'category_add'    ),
																 2 => array( 'act'           , 'shop'        ),
																 3 => array( 'section', $this->ipsclass->section_code ),
													 ) , "categoryaddform");

		//-----------------------------------------

		$this->ipsclass->adskin->td_header[] = array( "&nbsp;" , "50%" );
		$this->ipsclass->adskin->td_header[] = array( "&nbsp;" , "50%" );

		//-----------------------------------------

		$this->ipsclass->html .= $this->ipsclass->adskin->start_table( "Add New Category" );

		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Category name</b>" ,
										  				        			 $this->ipsclass->adskin->form_input( 'categoryName' )
											                        )      );

		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Category description</b>" ,
										  				         			$this->ipsclass->adskin->form_textarea( 'categoryDesc')
											                        )      );

		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Category Path</b><div style='color:gray'>The path that store the image items.<br />Example: if you enter <b>pets</b>, your image in this category will be saved to {$this->ipsclass->vars['upload_url']}/shop/<b>pets</b></div>" ,
										  				         			  $this->ipsclass->adskin->form_input( 'categoryPath')
																	)      );

		$this->ipsclass->html .= $this->ipsclass->adskin->end_form("Add Category");

		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();

		$this->ipsclass->admin->output();
	}
}


?>